package com.xz.freshmall.taomi.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.VideoView;

/**

 * @version 1.0

 * @date 2020/8/6  11:39
 */
public class HVideoView extends VideoView {
    private int width=0,height=0;
    public HVideoView(Context context) {
        super(context);
    }

    public HVideoView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public HVideoView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setMeasure(int width, int height) {

        this.width = width;

        this.height = height;

    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

// 默认高度，为了自动获取到focus

        int width = MeasureSpec.getSize(widthMeasureSpec);

        int height = width;

// 这个之前是默认的拉伸图像

        if (this.width > 0 && this.height > 0)

        {

            width = this.width;

            height = this.height;

        }

        setMeasuredDimension(width, height);

    }
//    @Override
//    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//        int wid = getDefaultSize(0, widthMeasureSpec);
//        int hei = getDefaultSize(0, heightMeasureSpec);
//        setMeasuredDimension(wid, hei);
//    }
}
